<?php namespace Admin\Controller;
/*
 * 员工控制器
 * */
	class StaffController extends CommonController
	{
		protected $db;
		/*
		 * 构造方法
		 * */
		public function __init()
		{
			$this->db = new \Common\Model\staff;
			//$this->db=1;
		}
		/*
		 * index方法
		 * */
		public function index()
		{
			$data = $this->db->get(); 
			View::with("data",$data);
			View::make();
		}
		/*
		 * 添加员工方法
		 * */
		public function addstaff()
		{
			//p($this->db);die;
			if(IS_POST){
				//p($_POST);die;
				if(!$this->db->addstaff()){
					View::error($this->db->getError());
				}else{
					View::success("添加成功",U("Staff/index"));
				}
			}
			View::make();
		}
		/*
		 * 编辑员工
		 * */
		public function resetstaff()
		{
			//获得所要编辑数据的id
			$sid = Q("get.sid",0,"intval");
			//p($sid);die;
			if(IS_POST){
				if(!$this->db->resetstaff()){
					View::error($this->db->getError());
				}else{
					View::success("编辑成功",U("Staff/index"));
				}
			}
			//获得元数据
			$olddata = $this->db->where("sid",$sid)->first();
			View::with("olddata",$olddata);
			View::make();
		}
		/*
		 * 删除
		 * */
		public function del()
		{
			//获得将要删除的sid
			$sid = Q("get.sid",0,"intval");
			
			if(!$this->db->del($sid)){
				View::error($this->db->del());
			}else{
				View::success("删除成功",U("Staff/index"));
			}
		}
	}
